#OrangePi linux SDK
#produced by cazure finish
#Welcome to my website 
#http://www.soilhead.cn/static/orangepi.html
############################################
Q=@
ECHO=echo
RUN=./script/sdk_main.sh
.PHONY: all clean help
.PHONY: uboot kernel busybox
.PHONY: uboot_config kernel_config busybox_config
.PHONY: rootfs image bootimage
.PHONY: tools sunxi-tools u-boot-tools gcc-tools
.PHONY: fex2bin bin2fex mkimage
.PHONY: boot.scr script.bin

all: clean uboot kernel busybox

clean:
	$(Q)$(ECHO) "clean OrangePi SDK"
	$(Q)$(RUN) clean
	
uboot :
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "build OrangePi uboot"
	$(Q)$(RUN) make uboot

uboot_config :
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "config OrangePi uboot"
	$(Q)$(RUN) config uboot

kernel :
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "build OrangePi kernel"
	$(Q)$(RUN) make kernel

kernel_config :
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "config OrangePi kernel"
	$(Q)$(RUN) config kernel

busybox :
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "build OrangePi busybox"
	$(Q)$(RUN) make busybox

busybox_config :
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "config OrangePi busybox"
	$(Q)$(RUN) config busybox

rootfs :
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "build OrangePi rootfs"
	$(Q)$(RUN) build rootfs

image :
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "build OrangePi uboot"
	$(Q)$(RUN) build image

bootimage :
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "build OrangePi bootimage"
	$(Q)$(RUN) build bootimage

tools: gcc-tools sunxi-tools u-boot-tools
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "OrangePi build tools "
	$(Q)$(RUN) 

script.bin:
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "build script.bin"
	$(Q)$(RUN) 

boot.scr:
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "build boot.scr"
	$(Q)$(RUN)
 
%.ext4: %.tar.gz
	$(Q)scripts/mk_ext4_rootfs.sh $< $@

update:
	$(Q)$(ECHO) ""
	$(Q)$(ECHO) "update OrangePi SDK"
	$(Q)git stash
	$(Q)git pull --rebase
	$(Q)git submodule -q init 
	$(Q)git submodule -q foreach git stash save -q --include-untracked "make update stash"
	-$(Q)git submodule -q foreach git fetch -q
	-$(Q)git submodule -q foreach "git rebase origin HEAD || :"
	-$(Q)git submodule -q foreach "git stash pop -q || :"
	-$(Q)git stash pop -q
	$(Q)git submodule status

help:
	$(Q)$(RUN) help


